﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.Collections;

using Model.WWW_User.User;
using BLL.WWW_User.Contacts;
using Model;
namespace BLF.WWW_WWW.Contact
{
    /// <summary>
    /// Contact 的摘要说明
    /// </summary>
    public class Contacts
    {
        /// <summary>
        /// 缓存时间（分钟）
        /// </summary>
        private const int CacheTime = 1;        
        /// <summary>
        /// 搜索会员(第一次获取)（0：会员列表UserSummaryInfoModel List、1：搜索数量int、2：当前会员语言信息）
        /// </summary>
        /// <param name="learnL">学习语言</param>
        /// <param name="speakL">母语</param>
        /// <param name="nation">来自国家</param>
        /// <param name="maxAge">最大年龄</param>
        /// <param name="minAge">最小年龄</param>
        /// <param name="gender">性别（0女、1男、空默认）</param>
        /// <param name="isAvatar">是否只显示有头像会员（1显示只有头像的会员，0默认）</param>
        /// <param name="isChatNow">是否只显示能聊天的会员</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="memberno">当前会员号</param>
        /// <returns>(0：会员列表UserSummaryInfoModel List、1：搜索数量int、2：当前会员语言信息)</returns>
        public static ArrayList GetMembers(string learnL, string speakL, string nation, string maxAge, string minAge, string gender, bool isAvatar, bool isChatNow, int pageIndex, int pageSize, string memberno)
        {
            return (new ContactsSystem()).GetMembers(learnL, speakL, nation, int.Parse(maxAge), int.Parse(minAge), gender, isAvatar, isChatNow, pageIndex, pageSize, memberno);
        }
        /// <summary>
        /// 搜索会员（0：会员列表UserSummaryInfoModel List、1：搜索数量int）
        /// </summary>
        /// <param name="learnL">学习语言</param>
        /// <param name="speakL">母语</param>
        /// <param name="nation">来自国家</param>
        /// <param name="maxAge">最大年龄</param>
        /// <param name="minAge">最小年龄</param>
        /// <param name="gender">性别（0女、1男、空默认）</param>
        /// <param name="city">当前所在城市</param>
        /// <param name="isAvatar">是否只显示有头像会员（1显示只有头像的会员，0默认）</param>
        /// <param name="isChatNow">是否只显示能聊天的会员</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="memberno">当前会员号</param>
        /// <returns>（0：会员列表UserSummaryInfoModel List、1：搜索数量int）</returns>        
        public static ArrayList GetMembers(string learnL, string speakL, string nation, string maxAge, string minAge, string gender, string city, bool isAvatar, bool isChatNow, int pageIndex, int pageSize, string memberno)
        {
            string key = string.Format("Contacts_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}_{10}", learnL, speakL, nation, maxAge, minAge, gender, isAvatar, isChatNow, memberno, pageIndex, pageSize);
            ArrayList arrayList = (ArrayList)BizObject.Cache[key];
            if (arrayList == null || city != "")
            {
                arrayList = (new ContactsSystem()).GetMembers(learnL, speakL, nation, int.Parse(maxAge), int.Parse(minAge), gender, city, isAvatar, isChatNow, pageIndex, pageSize, memberno);
                int recordCount = (int)arrayList[1];
                arrayList.RemoveAt(1);
                arrayList.Add(new BLF.PageableObject(recordCount, pageIndex, pageSize));
                BizObject.Cache.Insert(key, arrayList, null, DateTime.Now.AddMinutes(CacheTime), TimeSpan.Zero);
            }
            return arrayList;             
        }
        /// <summary>
        /// 搜索会员（0：会员列表UserSummaryInfoModel List、1：搜索数量int）
        /// </summary>
        /// <param name="nnMnMe">昵称名或会员email或会员号</param>
        /// <param name="pageIndex">页索引</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="memberno">当前会员号</param>
        /// <returns>0：会员列表UserSummaryInfoModel List、1：搜索数量int</returns>
        public static ArrayList GetSMembers(string nnMnMe, string memberno, int pageIndex, int pageSize)
        {
            ArrayList arrayList = (new ContactsSystem()).GetSMembers(nnMnMe, memberno, pageIndex, pageSize);
            int recordCount = (int)arrayList[1];
            arrayList.RemoveAt(1);
            arrayList.Add(new BLF.PageableObject(recordCount, pageIndex, pageSize));
            return arrayList;             
        }
        /// <summary>
        /// 根据当前会员号获取会员相关信息
        /// </summary>
        /// <param name="memberno">当前会员号</param>
        /// <param name="outList">输出列表（0好友数量，1接受请求数量，2发送请求数量，3会员列表）</param>
        /// <returns>操作消息</returns>
        public static Model.CommonMessage GetMyContacts(string memberno, int pageIndex, int pageSize, out ArrayList outList)
        {
            return (new ContactsSystem()).GetMyContacts(memberno, pageIndex, pageSize, out outList);
        }
        /// <summary>
        /// 根据当前会员号获取会员相关信息
        /// </summary>
        /// <param name="memberno">当前会员号</param>
        /// <param name="memberType">获取会员类型（0结交新朋友信息，1我的好友信息，2我收到请求的会员信息，3我发送请求的会员信息）</param>
        /// <param name="pageIndex">pageIndex</param>
        /// <param name="pageSize">pageSize</param>
        /// <param name="recordCount">输出记录</param>
        /// <returns>会员列表</returns>
        public static ArrayList GetContactMembers(string memberno, int memberType, int pageIndex, int pageSize)
        {
            ArrayList arrayList = new ArrayList();
            int recordCount = 0;
            List<UserSummaryInfoModel> userList = (new ContactsSystem()).GetContactMembers(memberno, memberType, pageIndex, pageSize, out recordCount);
            arrayList.Add(new BLF.PageableObject(recordCount, pageIndex, pageSize));
            arrayList.Add(userList);
            return arrayList;
        }
        /// <summary>
        /// 删除联系人
        /// </summary>
        ///<param name="myMemberno">我的会员号</param>
        /// <param name="fMemberno">朋友的会员号</param>
        /// <returns>CommonMessage</returns>
        public static CommonMessage DeleContacts(string myMemberno, string fMemberno)
        {
            return (new ContactsSystem()).DeleContacts(myMemberno, fMemberno);
        }
        /// <summary>
        /// 同意添加朋友
        /// </summary>
        ///<param name="myMemberno">我的会员号</param>
        /// <param name="fMemberno">朋友的会员号</param>
        /// <returns>CommonMessage</returns>
        public static CommonMessage AcceptFriend(string myMemberno, string fMemberno)
        {
            return (new ContactsSystem()).AcceptFriend(myMemberno, fMemberno);
        }
        /// <summary>
        /// 添加新朋友Effect 1:添加成功, 0:好友数量超限, 2:已经是联系人
        /// </summary>        
        /// <param name="myMemberno">我的会员号</param>
        /// <param name="fMemberno">添加的会员号</param>
        /// <returns>CommonMessage Effect 1:添加成功, 0:好友数量超限, 2:已经是联系人</returns>
        public static CommonMessage AddNewFriend(string myMemberno, string fMemberno)
        {
            return (new ContactsSystem()).AddNewFriend(myMemberno, fMemberno);
        }
        /// <summary>
        /// 邀请好友（CommonMessage.Effect＝0时表示此email不是italki会员，＝10时表示与当前会员有联系关系）
        /// </summary>
        /// <param name="memberno">当前会员号</param>
        /// <param name="fEmail">查询email</param>
        /// <param name="outList">0输出会员昵称(string)，1输出email对应会员的信息(UserNotifiModel)</param>
        /// <returns>CommonMessage</returns>
        public static CommonMessage InviteFriend(string memberno, string fEmail, out ArrayList outList)
        {
            return (new ContactsSystem()).InviteFriend(memberno, fEmail, out outList);
        }
        /// <summary>
        /// 判断两个会员之间的关系Effect 1:可以添加, 2:我的好友超限,3:添加人的好友超限
        /// </summary>
        /// <param name="memberno">当前会员号</param>
        /// <param name="fMemberno">添加的会员号</param>
        /// <param name="friendInfo">输出列表（0:(bool)IsFriend,1:(bool)IsLink,2:(bool)IsAgreeFriend,3:(int)EmailOption,
        /// 4:(string)添加朋友的昵称,5:(string)当前会员昵称,6:(string)添加朋友的email）</param>
        /// <returns>CommonMessage Effect 1:可以添加, 2:我的好友超限,3:添加人的好友超限</returns>
        public static CommonMessage MemberRelation(string memberno, string fMemberno, out ArrayList friendInfo)
        {
            return (new ContactsSystem()).MemberRelation(memberno, fMemberno, out friendInfo);
        }
        /// <summary>
        /// 获取会员好友列表(Nickname,MemberNo,Avatar)
        /// </summary>
        /// <param name="memberno">当前会员号</param>
        /// <param name="pageIndex">pageIndex</param>
        /// <param name="pageSize">pageSize</param>
        /// <param name="outList">输出：0:(int)数量,1:(List MemberSimpleModel)会员好友列表(Nickname,MemberNo,Avatar),
        /// 2:(string)当前用户昵称名,3:(List string)所有朋友号</param>
        /// <returns>CommonMessage</returns>
        public static CommonMessage GetMemberFriends(string memberno, int pageIndex, int pageSize, out ArrayList outList)
        {
            return (new ContactsSystem()).GetMemberFriends(memberno, pageIndex, pageSize, out outList);
        }
        /// <summary>
        /// 获取会员好友列表MemberSimpleModel(Nickname,MemberNo,Avatar)
        /// </summary>
        /// <param name="memberno">当前会员号</param>
        /// <param name="pageIndex">pageIndex</param>
        /// <param name="pageSize">pageSize</param>           
        /// <returns>MemberSimpleModel列表</returns>
        public static ArrayList GetMemberFriends(string memberno, int pageIndex, int pageSize)
        {
            ArrayList arrayList = new ArrayList();
            int recordCount;            
            List<Model.WWW_User.User.MemberSimpleModel> friendList = (new ContactsSystem()).GetMemberFriends(memberno, pageIndex, pageSize, out recordCount);
            arrayList.Add(friendList);
            arrayList.Add(new BLF.PageableObject(recordCount, pageIndex, pageSize));
            return arrayList;            
        }
        /// <summary>
        /// 获取ShareRes相关信息（0：当前会员好友数量、1：朋友信息（号、昵称）、2：当前会员昵称名）
        /// </summary>
        /// <param name="memberno">当前会员号</param>
        /// <param name="pageIndex">pageIndex</param>
        /// <param name="pageSize">pageSize</param>
        /// <returns>ArrayList（0：所有朋友（号、昵称）、1：当前会员昵称名）</returns>
        public static ArrayList GetShareResInfo(string memberno, int pageIndex, int pageSize)
        {
            return (new ContactsSystem()).GetShareResInfo(memberno, pageIndex, pageSize);
        }
        /// <summary>
        /// 得到会员的好友信息
        /// </summary>
        /// <param name="memberNo">会员号</param>
        /// <param name="pageIndex">页码</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="recordCount">输出总记录数</param>
        /// <param name="nickName">输出会员昵称</param>
        /// <returns>List（UserSummaryInfoModel）</returns>
        public static ArrayList GetLinkManUserInfo(string memberNo, int pageIndex, int pageSize)
        {
            int recordCount = 0;
            string nickName = "";
            ArrayList returnValue = new ArrayList();
            ContactsSystem lms = new ContactsSystem();
            List<Model.WWW_User.User.UserSummaryInfoModel> cm = lms.GetLinkManUserInfo(memberNo, pageIndex, pageSize, out recordCount, out nickName);
            returnValue.Add(new PageableObject(recordCount, pageIndex, pageSize));
            returnValue.Add(cm.ToArray());
            returnValue.Add(recordCount);
            returnValue.Add(nickName);
            return returnValue;
        }
        /// <summary>
        /// 联系人操作，返回CommonMessage(CommonMessage.Effect(0不存在1已经是好友2操作成功),CommonMessage.Msg:好友Email||好友Baselanguage||自己nickname||好友nickname）
        /// </summary>
        /// <param name="myMemberno">我的编号</param>
        /// <param name="fMemberno">朋友编号</param>
        /// <param name="opValue">操作值(true 同意加为好友，false 拒绝加为好友)</param>
        /// <returns>返回CommonMessage(CommonMessage.Effect(0不存在1已经是好友2操作成功),CommonMessage.Msg:好友Email||好友Baselanguage||自己nickname||好友nickname）</returns>
        public static CommonMessage OpContacts(string myMemberno, string fMemberno, bool opValue)
        {
            return (new ContactsSystem()).OpContacts(myMemberno, fMemberno, opValue);
        }
        /// <summary>
        /// 获取共享标题（share文件共享）
        /// </summary>
        /// <param name="type">1:问题标题,2:File标题</param>
        /// <param name="number">标题号</param>
        /// <returns>标题</returns>
        public static string Title(int type, string number)
        {
            return (new ContactsSystem()).Title(type, number);
        }
        /// <summary>
        /// 共享资源发送站内信
        /// </summary>
        /// <param name="myMemberno">我的编号</param>
        /// <param name="friendsMns">朋友编号列表</param>
        /// <param name="title">标题</param>
        /// <param name="body">内容</param>
        /// <param name="CheckAOrF">是否全选标记（true表示全选、如果friendsMn不为空表示不选择这些人）</param>
        /// <returns>CommonMessage</returns>
        public static CommonMessage ShareResSendMail(string myMemberno, string friendsMns, string title, string body, bool CheckAOrF)
        {
            return (new ContactsSystem()).ShareResSendMail(myMemberno, friendsMns, title, body, CheckAOrF);
        }

        #region Partner
        /// <summary>
        /// 获取用户搜索语言伙伴结果（0：结果数量int，1：用户语言伙伴列表UserSummaryInfoModel list）
        /// </summary>
        /// <param name="memberno">当前会员号</param>
        /// <param name="ll">学习语言</param>
        /// <param name="bl">使用试验</param>
        /// <param name="nation">国籍</param>
        /// <param name="maxAge">最大年龄</param>
        /// <param name="minAge">最小年龄</param>
        /// <param name="gender">性别（0女、1男、空默认）</param>
        /// <param name="isAvatar">是否只显示有头像会员（1显示只有头像的会员，0默认）</param>
        /// <param name="nativeBL">是否只显示母语1为ll的会员（1显示只有母语1为LL的会员，0随便哪个母语）</param>
        /// <param name="pageIndex">pageIndex</param>
        /// <param name="pageSize">pageSize</param>
        /// <returns>0：结果数量int，1：用户语言伙伴列表UserSummaryInfoModel list</returns>
        public static ArrayList GetFindPartner(string memberno, string ll, string bl, string nation, string maxAge, string minAge, string gender, bool isAvatar, bool nativeBL, int pageIndex, int pageSize)
        {
            string key = string.Format("FindPartner_{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}", ll, bl, nation, maxAge, minAge, gender, isAvatar, nativeBL, pageIndex, pageSize);
            ArrayList arrayList = (ArrayList)BizObject.Cache[key];
            if (arrayList == null)
            {
                arrayList = new ContactsSystem().GetFindPartner(memberno, ll, bl, nation, int.Parse(maxAge), int.Parse(minAge), gender, isAvatar, nativeBL, pageIndex, pageSize);
                BizObject.Cache.Insert(key, arrayList, null, DateTime.Now.AddHours(IProvider.Common.CacheTime), TimeSpan.Zero);
            }
            return arrayList;
        }
        /// <summary>
        /// 根据详细信息获取用户搜索语言伙伴（0：结果数量int，1：用户语言伙伴列表UserSummaryInfoModel list）
        /// </summary>
        /// <param name="nnMnMe">昵称名或会员email或会员号</param>
        /// <param name="memberno">当前会员号</param>
        /// <param name="pageIndex">pageIndex</param>
        /// <param name="pageSize">pageSize</param>
        /// <returns>（0：结果数量int，1：用户语言伙伴列表UserSummaryInfoModel list）</returns>
        public static ArrayList GetFindPartner_MN(string nnMnMe, string memberno, int pageIndex, int pageSize)
        {
            return new ContactsSystem().GetFindPartner_MN(nnMnMe, memberno, pageIndex, pageSize);
        }
        /// <summary>
        /// 根据爱好获取用户搜索语言伙伴（0：结果数量int，1：用户语言伙伴列表UserSummaryInfoModel list）
        /// </summary>
        /// <param name="favorite">兴趣</param>
        /// <param name="memberno">当前会员号</param>
        /// <param name="pageIndex">pageIndex</param>
        /// <param name="pageSize">pageSize</param>
        /// <returns>（0：结果数量int，1：用户语言伙伴列表UserSummaryInfoModel list）</returns>
        public static ArrayList GetPartner_Favorite(int favorite, string memberno, int pageIndex, int pageSize)
        {
            return new ContactsSystem().GetPartner_Favorite(favorite, memberno, pageIndex, pageSize);
        }
        /// <summary>
        /// 根据当前所在国家搜索用户语言伙伴（0：结果数量int，1：用户语言伙伴列表UserSummaryInfoModel list）
        /// </summary>
        /// <param name="country">当前所在国家</param>
        /// <param name="memberno">当前会员号</param>
        /// <param name="pageIndex">pageIndex</param>
        /// <param name="pageSize">pageSize</param>
        /// <returns>（0：结果数量int，1：用户语言伙伴列表UserSummaryInfoModel list）</returns>
        public static ArrayList GetPartner_Country(string country, string memberno, int pageIndex, int pageSize)
        {
            return new ContactsSystem().GetPartner_Country(country, memberno, pageIndex, pageSize);
        }
        /// <summary>
        /// 获取Categories页的数据 (0：活跃的MemberSimpleModel List、1：最新的MemberSimpleModel List)
        /// </summary>
        /// <param name="ll">学习语言</param>
        /// <returns>ArrayList</returns>
        public static ArrayList GetCategoriesMember(string ll)
        {
            string key = string.Format("PartnerCategories_{0}", ll);
            ArrayList arrayList = (ArrayList)BizObject.Cache[key];
            if (arrayList == null)
            {
                arrayList = new ContactsSystem().GetCategoriesMember(ll);
                BizObject.Cache.Insert(key, arrayList, null, DateTime.Now.AddHours(IProvider.Common.CacheTime12), TimeSpan.Zero);
            }
            return arrayList;            
        }        
        #endregion

        #region
        /// <summary>
        /// 根据爱好值获取兴趣爱好文本
        /// </summary>
        /// <param name="value">value</param>
        /// <returns>兴趣爱好文本</returns>
        public static string GetFavorite(int value)
        {
            string va = "";
            switch (value)
            {
                case 1:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB042");
                    break;
                case 2:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB043");
                    break;
                case 4:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB044");
                    break;
                case 8:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB045");
                    break;
                case 16:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB046");
                    break;
                case 32:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB047");
                    break;
                case 64:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB049");
                    break;
                case 128:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB048");
                    break;
                case 256:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB050");
                    break;
                case 512:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "PB051");
                    break;
                case 1024:
                    va = Lx.Web.Common.Resource.GetText(Lx.Web.Common.UI.Globals.Language, "C0087");
                    break;
            }
            return va;
        }
        #endregion
    }
}
